#include <stdio.h>
#include <stdlib.h>

#include "alg.h"

int
null(const void *jimmy, const void *aaron)
{
	return 0;
}

int
numcmp(const void *p1, const void *p2)
{
	const int a = * (const int *) p1,
	          b = * (const int *) p2;

	if (a < b) {
		fprintf(stderr, "%s(): %d < %d\n", __func__, a, b);
		return -1;
	}
	if (a > b) {
		fprintf(stderr, "%s(): %d > %d\n", __func__, a, b);
		return 1;
	}
	fprintf(stderr, "%s(): %d = %d\n", __func__, a, b);
	return 0;
}

int
main(int argc, char **argv)
{
	struct pqueue *PQ;
	int num, prev = -1;

	PQ = pqueue__new(sizeof (int), 0, true, &numcmp);
	/*PQ = pqueue__new(sizeof (int), 0, true, &null);*/
	while (scanf("%d", &num) == 1)
		pqueue__insert(PQ, &num);

	while (PQ->n) {
		pqueue__extract(PQ, &num);
		printf("%d\n", num);
		if (prev != -1 && prev > num) {
			printf("ordering error: "
					"previous integer %d "
					"was larger than the current %d\n",
					prev, num);
			debug_fprintf((stdout, "%s(): PQ->n=%d\n",
					__func__, PQ->n));
		}
		prev = num;
	}

	pqueue__cleanup(PQ);

	return 0;
}
